﻿using System.Collections.Generic;
using DataEntities;
using Repositories.Repository;
using Repositories.UoW;
using NUnit.Framework;

namespace TestRepositories
{

    [TestFixture]
    public class TestPeopleRepository:ITestRepository
    {
        private IPeopleRepository _repository;
        private IDogovorRepository _dogovorRepository;
        private RepositoryFactory _repositoryFactory;
        private People _people;

        #region Implementation of ITestRepository

        [SetUp]
        public void SetUp()
        {
            SessionFactory.Init();
            SessionFactory.GetSession().Flush();
            _repositoryFactory = new RepositoryFactory();
            _repository = _repositoryFactory.GetPeopleRepository();
            _dogovorRepository = _repositoryFactory.GetDogovorRepository();
        }

        [TearDown]
        public void CleanUp()
        {
            
        }

        [Test]
        public void TestGet()
        {
            Assert.AreEqual(78,_repository.Get(78).Id);
            Assert.AreEqual(18,_repository.Get(82).Dogovor.Id);
            Assert.AreEqual("Новикова",_repository.Get(86).SurName);
        }

        [Test]
        [Ignore]
        public void TestGetList()
        {
            Assert.AreEqual(13212,_repository.GetList().Count);
        }

        [Test]
        public void TestInsert()
        {
            _people=new People(_dogovorRepository.Get(3),"name","surname","name1",10,"911","911",true,false,99999);
            Assert.AreEqual(1, _repository.Insert(_people));
            _people = new People(_dogovorRepository.Get(3), "name", "surname", "name1", 10, "911", "911", true, false, 99998);
            Assert.AreEqual(1,_repository.Insert(_people));
        }

        [Test]
        public void TestUpdate()
        {
            _people = _repository.Get(72);
            _people.SurName += " Updated";
            Assert.AreEqual(1,_repository.Update(_people));
        }

        [Test]
        [Ignore]
        public void TestDelete()
        {
            _people=new People(72);
            Assert.AreEqual(1,_repository.Delete(_people));
        }

        [Test]
        public void TestEquals()
        {
            _people=new People(74);
            Assert.AreEqual(_people,_repository.Get(74));
        }

        [Test]
        public void TestInsertList()
        {
            IList<People> list = new List<People>();

            list.Add(new People(_dogovorRepository.Get(3), "name", "surname", "name1", 10, "911", "911", true, false, 99990));
            list.Add(new People(_dogovorRepository.Get(3), "name", "surname", "name1", 10, "911", "911", true, false, 99991));
            list.Add(new People(_dogovorRepository.Get(3), "name", "surname", "name1", 10, "911", "911", true, false, 99992));
            Assert.AreEqual(3,_repository.InsertList(list));
        }

        [Test]
        public void UpdateList()
        {
            IList<People> list=new List<People>();
            list.Add(_repository.Get(76));
            list.Add(_repository.Get(95));
            list.Add(_repository.Get(88));
            list.Add(_repository.Get(102));

            foreach (People item in list)
            {
                item.SurName += " Updated List";
            }

            Assert.AreEqual(4,_repository.UpdateList(list));
        }

        [Test]
        [Ignore]
        public void TestDeleteList()
        {
            IList<People> list = new List<People>();
            list.Add(new People(72));
            list.Add(new People(73));
            list.Add(new People(74));
            list.Add(new People(75));

            Assert.AreEqual(4,_repository.DeleteList(list));
        }

        #endregion

        [Test]
        public void TestGetChildHistoryCreatedReceiptsList()
        {
            Assert.Fail("надо сделать");
        }

        [Test]
        public void TestGetChildHistoryPayedReceiptsList()
        {
            Assert.Fail("надо сделать");
        }
    }
}